﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using YellowMap.Resources;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Diagnostics;
using Microsoft.Phone.Tasks;
using YellowMap.View.Control;
using Microsoft.Phone.Maps.Controls;
using System.Device.Location;
using YellowMap.Ultility;

namespace YellowMap.View.Page
{
    public partial class SearchPage : PhoneApplicationPage
    {
        public CategoryModel.SubCate subCateFoodDrink;
        public CategoryModel.SubCate subCateTravel;
        public CategoryModel.SubCate subCateEntertainment;
        public CategoryModel.SubCate subCateEducation;
        public CategoryModel.SubCate subCateShopping;
        public CategoryModel.SubCate subCateService;
        public SearchPage Intance { get; set; }
        public static bool isStartApp = true;
        public static bool isFromSearchPage = false;
        public static bool isViewHistory = false;
        public static bool isSearchHistory = false;
        public static bool isViewFavorites = false;
        public static bool isSearchFavorites = false;
        public static bool isSetting = false;
        /*
        * [vttrung]: FT07
        */
        public SearchPage()
        {
            InitializeComponent();
            ReloadLanguage(AppViewModel.Instance.SettingVM.Language);
            
            //CheckLocationRadio();
            //CheckRankRadio();
            pivotCategory.SelectedIndex = AppViewModel.Instance.SettingVM.IndexCate;
            (ApplicationBar as ApplicationBar).BackgroundColor = AppViewModel.Instance.SettingVM.BGColor_Appbar;
            //tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
            LoadTheme();
            LoadImageSubCate();
            //if (AppViewModel.Instance.SettingVM.Language == "Vi")
            //    tbSearch.Text = LangVi.str_searchHintText;
            //else
            //    tbSearch.Text = LangEn.str_searchHintText;
            tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
            if (isStartApp)
            {
                isStartApp = false;
            }
            if (AppViewModel.Instance.SettingVM.Language == "Vi")
                tbSearch.Text = LangVi.str_searchHintText;
            else
                tbSearch.Text = LangEn.str_searchHintText;
        }

        private void CheckIndexSubCate()
        {

        }

        // Detect Theme of Search screen and Load theme to app
        private void LoadTheme()
        {
            pivotCategory.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
            titleBG.Stroke = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_titBG);
            titleBG.Fill = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_titBG);
            //radCurrentLocation.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
            //radChooseOnMap.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
            //radSearchClosest.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
            //radSearchBestRated.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
            if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] != Visibility.Visible)
            {
                pivotCategory.Foreground = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_Text);
                LayoutRoot.Background = new SolidColorBrush(AppViewModel.Instance.SettingVM.BGColor_screen);
                //ImageSearch.Source = new BitmapImage(new Uri("/Resources/NewIcon/search_normal.png", UriKind.Relative));
            }
        }

        // Load Language when change language in settings screen
        private void LoadImageSubCate()
        {
            if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible)
            {
                // food & drink
                AppViewModel.Instance.Categories[0].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_All.png";
                AppViewModel.Instance.Categories[0].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_America.png";
                AppViewModel.Instance.Categories[0].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Chinese.png";
                AppViewModel.Instance.Categories[0].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_VietNamese.png";
                AppViewModel.Instance.Categories[0].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Italian.png";
                AppViewModel.Instance.Categories[0].SubCategories[5].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Japanese.png";
                AppViewModel.Instance.Categories[0].SubCategories[6].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Mexican.png";
                AppViewModel.Instance.Categories[0].SubCategories[7].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Steak.png";
                AppViewModel.Instance.Categories[0].SubCategories[8].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Thai.png";
                AppViewModel.Instance.Categories[0].SubCategories[9].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_HappyHour.png";
                AppViewModel.Instance.Categories[0].SubCategories[10].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_FastFood.png";
                AppViewModel.Instance.Categories[0].SubCategories[11].ImageSource = "/Resources/SubCateIcon/Dark/foodDrink_Vegetarian.png";
                // travel
                AppViewModel.Instance.Categories[1].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/travel_Airport.png";
                AppViewModel.Instance.Categories[1].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/travel_CarRental.png";
                AppViewModel.Instance.Categories[1].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Dark/travel_Hotel.png";
                AppViewModel.Instance.Categories[1].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Dark/travel_Transportation.png";
                // entertainment
                AppViewModel.Instance.Categories[2].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Atraction.png";
                AppViewModel.Instance.Categories[2].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Casino.png";
                AppViewModel.Instance.Categories[2].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Cinema.png";
                AppViewModel.Instance.Categories[2].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Museum.png";
                AppViewModel.Instance.Categories[2].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_NightClub.png";
                AppViewModel.Instance.Categories[2].SubCategories[5].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Spa.png";
                AppViewModel.Instance.Categories[2].SubCategories[6].ImageSource = "/Resources/SubCateIcon/Dark/entertainment_Golf.png";
                // education
                AppViewModel.Instance.Categories[3].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/education_School.png";
                AppViewModel.Instance.Categories[3].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/education_University.png";
                AppViewModel.Instance.Categories[3].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Dark/education_Library.png";
                // shooping
                AppViewModel.Instance.Categories[4].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/shopping_Retail.png";
                AppViewModel.Instance.Categories[4].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/shopping_Outlet.png";
                // service
                AppViewModel.Instance.Categories[5].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Dark/service_Gas.png";
                AppViewModel.Instance.Categories[5].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Dark/service_BankATM.png";
                AppViewModel.Instance.Categories[5].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Dark/service_Law.png";
                AppViewModel.Instance.Categories[5].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Dark/service_RealState.png";
                AppViewModel.Instance.Categories[5].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Dark/service_Tax.png";
            }
            else
            {
                // food & drink
                AppViewModel.Instance.Categories[0].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_All.png";
                AppViewModel.Instance.Categories[0].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_America.png";
                AppViewModel.Instance.Categories[0].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Chinese.png";
                AppViewModel.Instance.Categories[0].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_VietNamese.png";
                AppViewModel.Instance.Categories[0].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Italian.png";
                AppViewModel.Instance.Categories[0].SubCategories[5].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Japanese.png";
                AppViewModel.Instance.Categories[0].SubCategories[6].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Mexican.png";
                AppViewModel.Instance.Categories[0].SubCategories[7].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Steak.png";
                AppViewModel.Instance.Categories[0].SubCategories[8].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Thai.png";
                AppViewModel.Instance.Categories[0].SubCategories[9].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_HappyHour.png";
                AppViewModel.Instance.Categories[0].SubCategories[10].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_FastFood.png";
                AppViewModel.Instance.Categories[0].SubCategories[11].ImageSource = "/Resources/SubCateIcon/Light/foodDrink_Vegetarian.png";
                // travel
                AppViewModel.Instance.Categories[1].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/travel_Airport.png";
                AppViewModel.Instance.Categories[1].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/travel_CarRental.png";
                AppViewModel.Instance.Categories[1].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Light/travel_Hotel.png";
                AppViewModel.Instance.Categories[1].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Light/travel_Transportation.png";
                // entertainment
                AppViewModel.Instance.Categories[2].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Atraction.png";
                AppViewModel.Instance.Categories[2].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Casino.png";
                AppViewModel.Instance.Categories[2].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Cinema.png";
                AppViewModel.Instance.Categories[2].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Museum.png";
                AppViewModel.Instance.Categories[2].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Light/entertainment_NightClub.png";
                AppViewModel.Instance.Categories[2].SubCategories[5].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Spa.png";
                AppViewModel.Instance.Categories[2].SubCategories[6].ImageSource = "/Resources/SubCateIcon/Light/entertainment_Golf.png";
                // education
                AppViewModel.Instance.Categories[3].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/education_School.png";
                AppViewModel.Instance.Categories[3].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/education_University.png";
                AppViewModel.Instance.Categories[3].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Light/education_Library.png";
                // shooping
                AppViewModel.Instance.Categories[4].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/shopping_Retail.png";
                AppViewModel.Instance.Categories[4].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/shopping_Outlet.png";
                // service
                AppViewModel.Instance.Categories[5].SubCategories[0].ImageSource = "/Resources/SubCateIcon/Light/service_Gas.png";
                AppViewModel.Instance.Categories[5].SubCategories[1].ImageSource = "/Resources/SubCateIcon/Light/service_BankATM.png";
                AppViewModel.Instance.Categories[5].SubCategories[2].ImageSource = "/Resources/SubCateIcon/Light/service_Law.png";
                AppViewModel.Instance.Categories[5].SubCategories[3].ImageSource = "/Resources/SubCateIcon/Light/service_RealState.png";
                AppViewModel.Instance.Categories[5].SubCategories[4].ImageSource = "/Resources/SubCateIcon/Light/service_Tax.png";
            }
            
        }
        private void ReloadLanguage(string languageName)
        {
            switch (languageName)
            {
                case "Vi":
                    (ApplicationBar.Buttons[0] as ApplicationBarIconButton).Text = LangVi.str_setting;
                    (ApplicationBar.Buttons[1] as ApplicationBarIconButton).Text = LangVi.str_favorites;
                    (ApplicationBar.Buttons[2] as ApplicationBarIconButton).Text = LangVi.str_history;
                    (ApplicationBar.Buttons[3] as ApplicationBarIconButton).Text = LangVi.str_search;
                    foodDrink.Header = LangVi.str_foodDrink;
                    travel.Header = LangVi.str_travel;
                    entertainment.Header = LangVi.str_entertainment;
                    education.Header = LangVi.str_education;
                    shopping.Header = LangVi.str_shopping;
                    service.Header = LangVi.str_service;
                    // food & drink
                    (ApplicationBar.MenuItems[0] as ApplicationBarMenuItem).Text = LangVi.strPolicyHeading;
                    (ApplicationBar.MenuItems[1] as ApplicationBarMenuItem).Text = LangVi.str_Feedback;
                    AppViewModel.Instance.Categories[0].SubCategories[0].Text = LangVi.foodDrink_all;
                    AppViewModel.Instance.Categories[0].SubCategories[1].Text = LangVi.foodDrink_America;
                    AppViewModel.Instance.Categories[0].SubCategories[2].Text = LangVi.foodDrink_Chinese;
                    AppViewModel.Instance.Categories[0].SubCategories[3].Text = LangVi.foodDrink_VietNamese;
                    AppViewModel.Instance.Categories[0].SubCategories[4].Text = LangVi.foodDrink_Italian;
                    AppViewModel.Instance.Categories[0].SubCategories[5].Text = LangVi.foodDrink_Japanese;
                    AppViewModel.Instance.Categories[0].SubCategories[6].Text = LangVi.foodDrink_Mexican;
                    AppViewModel.Instance.Categories[0].SubCategories[7].Text = LangVi.foodDrink_Steak;
                    AppViewModel.Instance.Categories[0].SubCategories[8].Text = LangVi.foodDrink_Thai;
                    AppViewModel.Instance.Categories[0].SubCategories[9].Text = LangVi.foodDrink_HappyHour;
                    AppViewModel.Instance.Categories[0].SubCategories[10].Text = LangVi.foodDrink_FastFood;
                    AppViewModel.Instance.Categories[0].SubCategories[11].Text = LangVi.foodDrink_Vegetarian;
                    // travel
                    AppViewModel.Instance.Categories[1].SubCategories[0].Text = LangVi.travel_Airport;
                    AppViewModel.Instance.Categories[1].SubCategories[1].Text = LangVi.travel_CarRental;
                    AppViewModel.Instance.Categories[1].SubCategories[2].Text = LangVi.travel_Hotel;
                    AppViewModel.Instance.Categories[1].SubCategories[3].Text = LangVi.travel_Transportation;
                    // entertainment
                    AppViewModel.Instance.Categories[2].SubCategories[0].Text = LangVi.entertainment_Atraction;
                    AppViewModel.Instance.Categories[2].SubCategories[1].Text = LangVi.entertainment_Casino;
                    AppViewModel.Instance.Categories[2].SubCategories[2].Text = LangVi.entertainment_Cinema;
                    AppViewModel.Instance.Categories[2].SubCategories[3].Text = LangVi.entertainment_Museum;
                    AppViewModel.Instance.Categories[2].SubCategories[4].Text = LangVi.entertainment_NightClub;
                    AppViewModel.Instance.Categories[2].SubCategories[5].Text = LangVi.entertainment_Spa;
                    AppViewModel.Instance.Categories[2].SubCategories[6].Text = LangVi.entertainment_Golf;
                    // education
                    AppViewModel.Instance.Categories[3].SubCategories[0].Text = LangVi.education_School;
                    AppViewModel.Instance.Categories[3].SubCategories[1].Text = LangVi.education_University;
                    AppViewModel.Instance.Categories[3].SubCategories[2].Text = LangVi.education_Library;
                    // shooping
                    AppViewModel.Instance.Categories[4].SubCategories[0].Text = LangVi.shopping_Retail;
                    AppViewModel.Instance.Categories[4].SubCategories[1].Text = LangVi.shopping_Outlet;
                    // service
                    AppViewModel.Instance.Categories[5].SubCategories[0].Text = LangVi.service_Gas;
                    AppViewModel.Instance.Categories[5].SubCategories[1].Text = LangVi.service_BankATM;
                    AppViewModel.Instance.Categories[5].SubCategories[2].Text = LangVi.service_Law;
                    AppViewModel.Instance.Categories[5].SubCategories[3].Text = LangVi.service_RealState;
                    AppViewModel.Instance.Categories[5].SubCategories[4].Text = LangVi.service_Tax;
                    break;
                case "En":
                    foodDrink.Header = LangEn.str_foodDrink;
                    travel.Header = LangEn.str_travel;
                    entertainment.Header = LangEn.str_entertainment;
                    education.Header = LangEn.str_education;
                    shopping.Header = LangEn.str_shopping;
                    service.Header = LangEn.str_service;
                    (ApplicationBar.Buttons[0] as ApplicationBarIconButton).Text = LangEn.str_setting;
                    (ApplicationBar.Buttons[1] as ApplicationBarIconButton).Text = LangEn.str_favorites;
                    (ApplicationBar.Buttons[2] as ApplicationBarIconButton).Text = LangEn.str_history;
                    (ApplicationBar.Buttons[3] as ApplicationBarIconButton).Text = LangEn.str_search;
                    (ApplicationBar.MenuItems[0] as ApplicationBarMenuItem).Text = LangEn.strPolicyHeading;
                    (ApplicationBar.MenuItems[1] as ApplicationBarMenuItem).Text = LangEn.str_Feedback;
                    //food & drink
                    AppViewModel.Instance.Categories[0].SubCategories[0].Text = LangEn.foodDrink_all;
                    AppViewModel.Instance.Categories[0].SubCategories[1].Text = LangEn.foodDrink_America;
                    AppViewModel.Instance.Categories[0].SubCategories[2].Text = LangEn.foodDrink_Chinese;
                    AppViewModel.Instance.Categories[0].SubCategories[3].Text = LangEn.foodDrink_VietNamese;
                    AppViewModel.Instance.Categories[0].SubCategories[4].Text = LangEn.foodDrink_Italian;
                    AppViewModel.Instance.Categories[0].SubCategories[5].Text = LangEn.foodDrink_Japanese;
                    AppViewModel.Instance.Categories[0].SubCategories[6].Text = LangEn.foodDrink_Mexican;
                    AppViewModel.Instance.Categories[0].SubCategories[7].Text = LangEn.foodDrink_Steak;
                    AppViewModel.Instance.Categories[0].SubCategories[8].Text = LangEn.foodDrink_Thai;
                    AppViewModel.Instance.Categories[0].SubCategories[9].Text = LangEn.foodDrink_HappyHour;
                    AppViewModel.Instance.Categories[0].SubCategories[10].Text = LangEn.foodDrink_FastFood;
                    AppViewModel.Instance.Categories[0].SubCategories[11].Text = LangEn.foodDrink_Vegetarian;
                    // travel
                    AppViewModel.Instance.Categories[1].SubCategories[0].Text = LangEn.travel_Airport;
                    AppViewModel.Instance.Categories[1].SubCategories[1].Text = LangEn.travel_CarRental;
                    AppViewModel.Instance.Categories[1].SubCategories[2].Text = LangEn.travel_Hotel;
                    AppViewModel.Instance.Categories[1].SubCategories[3].Text = LangEn.travel_Transportation;
                    // entertainment
                    AppViewModel.Instance.Categories[2].SubCategories[0].Text = LangEn.entertainment_Atraction;
                    AppViewModel.Instance.Categories[2].SubCategories[1].Text = LangEn.entertainment_Casino;
                    AppViewModel.Instance.Categories[2].SubCategories[2].Text = LangEn.entertainment_Cinema;
                    AppViewModel.Instance.Categories[2].SubCategories[3].Text = LangEn.entertainment_Museum;
                    AppViewModel.Instance.Categories[2].SubCategories[4].Text = LangEn.entertainment_NightClub;
                    AppViewModel.Instance.Categories[2].SubCategories[5].Text = LangEn.entertainment_Spa;
                    AppViewModel.Instance.Categories[2].SubCategories[6].Text = LangEn.entertainment_Golf;
                    // education
                    AppViewModel.Instance.Categories[3].SubCategories[0].Text = LangEn.education_School;
                    AppViewModel.Instance.Categories[3].SubCategories[1].Text = LangEn.education_University;
                    AppViewModel.Instance.Categories[3].SubCategories[2].Text = LangEn.education_Library;
                    // shooping
                    AppViewModel.Instance.Categories[4].SubCategories[0].Text = LangEn.shopping_Retail;
                    AppViewModel.Instance.Categories[4].SubCategories[1].Text = LangEn.shopping_Outlet;
                    // service
                    AppViewModel.Instance.Categories[5].SubCategories[0].Text = LangEn.service_Gas;
                    AppViewModel.Instance.Categories[5].SubCategories[1].Text = LangEn.service_BankATM;
                    AppViewModel.Instance.Categories[5].SubCategories[2].Text = LangEn.service_Law;
                    AppViewModel.Instance.Categories[5].SubCategories[3].Text = LangEn.service_RealState;
                    AppViewModel.Instance.Categories[5].SubCategories[4].Text = LangEn.service_Tax;
                    break;
            }
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (isFromSearchPage)
            {
                isFromSearchPage = false;
                if (isViewHistory)
                {
                    MainPage.COMMAND = MainPage_Command.SHOW_HISTORY;
                    isViewHistory = false;
                }
                else if (isSearchHistory)
                {
                    MainPage.COMMAND = MainPage_Command.SEARCH_HISTORY;
                    isSearchHistory = false;
                }
                else if (isViewFavorites)
                {
                    MainPage.COMMAND = MainPage_Command.SHOW_FAVORITE;
                    isViewFavorites = false;
                }
                else if (isSearchFavorites)
                {
                    MainPage.COMMAND = MainPage_Command.SEARCH_FAVORITE;
                    isSearchFavorites = false;
                }
                NavigationService.GoBack();
                checkivisibleMainPage();
                checkvisibletextbox();
            }
            else
            {
                ReloadLanguage(AppViewModel.Instance.SettingVM.Language);
                pivotCategory_SelectionChanged(null, null);
                base.OnNavigatedTo(e);
            }
            
        }
        private void exit()
        {
            while (NavigationService.BackStack.Any())
                NavigationService.RemoveBackEntry();
            
        }

        protected override async void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
           // AppLifetimeHelper.Instance.CloseApplication();

//#if DEBUG
//            await Logger.WriteLog("Exit Visual Map");
//#endif

            exit();
            base.OnBackKeyPress(e);

            
        }
        // Load the last Location radiobutton which user choose before search
        //private void CheckLocationRadio()
        //{
        //    if (AppViewModel.Instance.SettingVM.SearchFrom == 1)
        //    {
        //        radCurrentLocation.IsChecked = true;
        //    }
        //    else
        //    {
        //        radChooseOnMap.IsChecked = true;
        //    }
        //}

        //// Load the last Rank radiobutton which user choose before search
        //private void CheckRankRadio()
        //{
        //    if (AppViewModel.Instance.SettingVM.SearchBy == 1)
        //    {
        //        radSearchClosest.IsChecked = true;
        //    }
        //    else
        //    {
        //        radSearchBestRated.IsChecked = true;
        //    }
        //}


        //Save selected currentlocation to search
        private void radCurrentLocation_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            //AppViewModel.Instance.SettingVM.SearchFrom = Constant.SEARCH_FROM_MYLOCATION;
        }

        //Save selected ChooseOnMap to search
        private void radChooseOnMap_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
           // AppViewModel.Instance.SettingVM.SearchFrom = Constant.SEARCH_FROM_MAP;
        }

        //Save selected SearchClosest to search
        private void radSearchClosest_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
          //  AppViewModel.Instance.SettingVM.SearchBy = Constant.SEARCHBY_CLOSET;
        }

        //Save selected SearchBestRated to search
        private void radSearchBestRated_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            //AppViewModel.Instance.SettingVM.SearchBy = Constant.SEARCHBY_RATING;
        }


        // Handle changing pivot index
        private void pivotCategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            AppViewModel.Instance.SettingVM.IndexCate = pivotCategory.SelectedIndex;
            switch (pivotCategory.SelectedIndex)
            {
                case 0:
                    lbfoodDrink.ItemsSource = null;
                    if (lbfoodDrink.Items.Count > 0)
                    {
                        lbfoodDrink.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[0].SubCategories[AppViewModel.Instance.SettingVM.indexSubCateFoodDink].IsCheck = true;
                    subCateFoodDrink = AppViewModel.Instance.Categories[0].SubCategories[0];
                    lbfoodDrink.ItemsSource = AppViewModel.Instance.Categories[0].SubCategories;
                    break;
                case 1:
                    lbtravel.ItemsSource = null;
                    if (lbtravel.Items.Count > 0)
                    {
                        lbtravel.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[1].SubCategories[AppViewModel.Instance.SettingVM.indexSubTravel].IsCheck = true;
                    lbtravel.ItemsSource = AppViewModel.Instance.Categories[1].SubCategories;
                    subCateTravel = AppViewModel.Instance.Categories[1].SubCategories[0];
                    break;
                case 2:
                    lbentertainment.ItemsSource = null;
                    if (lbentertainment.Items.Count > 0)
                    {
                        lbentertainment.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[2].SubCategories[AppViewModel.Instance.SettingVM.indexSubEntertainment].IsCheck = true;
                    lbentertainment.ItemsSource = AppViewModel.Instance.Categories[2].SubCategories;
                    subCateEntertainment = AppViewModel.Instance.Categories[2].SubCategories[0];
                    break;
                case 3:
                    lbeducation.ItemsSource = null;
                    if (lbeducation.Items.Count > 0)
                    {
                        lbeducation.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[3].SubCategories[AppViewModel.Instance.SettingVM.indexSubEducation].IsCheck = true;
                    lbeducation.ItemsSource = AppViewModel.Instance.Categories[3].SubCategories;
                    subCateEducation = AppViewModel.Instance.Categories[3].SubCategories[0];
                    break;
                case 4:
                    lbshopping.ItemsSource = null;
                    if (lbshopping.Items.Count > 0)
                    {
                        lbshopping.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[4].SubCategories[AppViewModel.Instance.SettingVM.indexSubShopping].IsCheck = true;
                    lbshopping.ItemsSource = AppViewModel.Instance.Categories[4].SubCategories;
                    subCateShopping = AppViewModel.Instance.Categories[4].SubCategories[0];
                    break;
                case 5:
                    lbservice.ItemsSource = null;
                    if (lbservice.Items.Count > 0)
                    {
                        lbservice.Items.Clear();
                    }
                    AppViewModel.Instance.Categories[5].SubCategories[AppViewModel.Instance.SettingVM.indexSubService].IsCheck = true;
                    lbservice.ItemsSource = AppViewModel.Instance.Categories[5].SubCategories;
                    subCateService = AppViewModel.Instance.Categories[5].SubCategories[0];
                    break;
            }

        }



        // Handle when text box search lost focus
        //private void tbSearch_LostFocus(object sender, RoutedEventArgs e)
        //{
        //    if (isKeyDown == false)
        //    {
        //        tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
        //        if (AppViewModel.Instance.SettingVM.Language == "Vi")
        //            tbSearch.Text = LangVi.str_searchHintText;
        //        else
        //            tbSearch.Text = LangEn.str_searchHintText;
        //    }
        //    else if (isKeyDown == true && tbSearch.Text == "")
        //    {
        //        tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
        //        if (AppViewModel.Instance.SettingVM.Language == "Vi")
        //            tbSearch.Text = LangVi.str_searchHintText;
        //        else
        //            tbSearch.Text = LangEn.str_searchHintText;
        //    }
        //}

        //// handle when text box search got focus
        //private void tbSearch_GotFocus(object sender, RoutedEventArgs e)
        //{

        //    tbSearch.Foreground = new SolidColorBrush(Colors.Black);
        //    tbSearch.Text = "";
        //}



        #region change image of search image when usser tap on
        //private void ImageSearch_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        //{
        //    if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] != Visibility.Visible)
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/NewIcon/search_pressing.png", UriKind.Relative));
        //    else
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/Icon/search_pressing.png", UriKind.Relative));
        //}

        //private void ImageSearch_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        //{
        //    if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] != Visibility.Visible)
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/NewIcon/search_normal.png", UriKind.Relative));
        //    else
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/Icon/search_normal.png", UriKind.Relative));
        //}

        //private void ImageSearch_Hold(object sender, System.Windows.Input.GestureEventArgs e)
        //{
        //    if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] != Visibility.Visible)
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/NewIcon/search_pressing.png", UriKind.Relative));
        //    else
        //        ImageSearch.Source = new BitmapImage(new Uri("/Resources/Icon/search_pressing.png", UriKind.Relative));
        //}
        //bool isKeyDown = false;
        //private void tbSearch_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        //{
        //    isKeyDown = true;
        //}
        #endregion


        // Handle searching when user tap onl search image
        //private void ImageSearch_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        //{
        //    tbSearch.Text = tbSearch.Text.Trim();

        //    if (tbSearch.Text.Contains(","))
        //    {
        //        string[] strsLocation = tbSearch.Text.Split(new char[] { ',' });
        //        float lat = 0;
        //        float lng = 0;
        //        if (strsLocation.Length == 2)
        //        {
        //            if (float.TryParse(strsLocation[0].Trim(), out lat) && float.TryParse(strsLocation[1].Trim(), out lng))
        //            {
        //                MainPage.move_map_lat = lat;
        //                MainPage.move_map_lng = lng;
        //                MainPage.COMMAND = MainPage_Command.MOVE_MAP;
        //                NavigationService.GoBack();
        //                return;
        //            }
        //        }

        //    }

        //    switch (pivotCategory.SelectedIndex)
        //    {
        //        case 0:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.FoodItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateFoodDrink.Id;
        //            break;
        //        case 1:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.TravelItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateTravel.Id;
        //            break;
        //        case 2:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EntertainmentItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateEntertainment.Id;
        //            break;
        //        case 3:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EducationItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateEducation.Id;
        //            break;
        //        case 4:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ShoppingItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateShopping.Id;
        //            break;
        //        case 5:
        //            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ServiceItem;
        //            //AppViewModel.Instance.SettingVM.SubCate = subCateService.Id;
        //            break;
        //    }
        //    if (tbSearch.Text == LangVi.str_searchHintText || tbSearch.Text == LangEn.str_searchHintText)
        //    {
        //        MainPage.SearchKeyword = "";
        //    }
        //    else if (tbSearch.Text == "")
        //    {
        //        MainPage.SearchKeyword = "";
        //    }
        //    else
        //    {
        //        MainPage.SearchKeyword = tbSearch.Text;
        //    }
        //    MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
        //    NavigationService.GoBack();
        //}

        private void checkivisibleMainPage()
        {
            if (MainPage.Instance.LayoutMainPageScreen.Visibility == System.Windows.Visibility.Collapsed)
            {
                MainPage.Instance.LayoutMainPageScreen.Visibility = System.Windows.Visibility.Visible;
            }
        }
        private void checkvisibletextbox()
        {
            if (MainPage.Instance.tbSearch.Visibility == System.Windows.Visibility.Visible)
            {
                MainPage.Instance.tbSearch.Visibility = System.Windows.Visibility.Collapsed;
                MainPage.Instance.titleBG.Visibility = System.Windows.Visibility.Collapsed;
                MainPage.Instance.imagesearch.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubCateFoodDink = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.FoodItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.FoodItem;
            //RadioButton rad = sender as RadioButton;
            //subCateFoodDrink = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[0].SubCategories[AppViewModel.Instance.SettingVM.indexSubCateFoodDink].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubCateFoodDink = AppViewModel.Instance.SubCateId[subCateFoodDrink.Id];
            //AppViewModel.Instance.SettingVM.FoodItem = subCateFoodDrink.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.FoodItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            checkivisibleMainPage();
            NavigationService.GoBack();
            //MainPage.Instance.CheckInternet();
            checkvisibletextbox();
            
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubTravel = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.TravelItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.TravelItem;
            //RadioButton rad = sender as RadioButton;
            //subCateTravel = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[1].SubCategories[AppViewModel.Instance.SettingVM.indexSubTravel].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubTravel = AppViewModel.Instance.SubCateId[subCateTravel.Id];
            //AppViewModel.Instance.SettingVM.TravelItem = subCateTravel.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.TravelItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            NavigationService.GoBack();
            checkivisibleMainPage();
            checkvisibletextbox();
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_3(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubEntertainment = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.EntertainmentItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EntertainmentItem;
            //RadioButton rad = sender as RadioButton;
            //subCateEntertainment = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[2].SubCategories[AppViewModel.Instance.SettingVM.indexSubEntertainment].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubEntertainment = AppViewModel.Instance.SubCateId[subCateEntertainment.Id];
            //AppViewModel.Instance.SettingVM.EntertainmentItem = subCateEntertainment.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EntertainmentItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            NavigationService.GoBack();
            checkivisibleMainPage();
            checkvisibletextbox();
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_4(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubEducation = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.EducationItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EducationItem;
            //RadioButton rad = sender as RadioButton;
            //subCateEducation = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[3].SubCategories[AppViewModel.Instance.SettingVM.indexSubEducation].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubEducation = AppViewModel.Instance.SubCateId[subCateEducation.Id];
            //AppViewModel.Instance.SettingVM.EducationItem = subCateEducation.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.EducationItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            NavigationService.GoBack();
            checkivisibleMainPage();
            checkvisibletextbox();
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_5(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubShopping = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.ShoppingItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ShoppingItem;
            //RadioButton rad = sender as RadioButton;
            //subCateShopping = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[4].SubCategories[AppViewModel.Instance.SettingVM.indexSubShopping].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubShopping = AppViewModel.Instance.SubCateId[subCateShopping.Id];
            //AppViewModel.Instance.SettingVM.ShoppingItem = subCateShopping.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ShoppingItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            NavigationService.GoBack();
            checkivisibleMainPage();
            checkvisibletextbox();
        }
        // Save seletetion of user when choose subcate
        private void RadioButton_Tap_6(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string id = (sender as StackPanel).Tag.ToString();
            AppViewModel.Instance.SettingVM.indexSubService = AppViewModel.Instance.SubCateId[id];
            AppViewModel.Instance.SettingVM.ServiceItem = id;
            AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ServiceItem;
            //RadioButton rad = sender as RadioButton;
            //subCateService = rad.DataContext as CategoryModel.SubCate;
            //AppViewModel.Instance.Categories[5].SubCategories[AppViewModel.Instance.SettingVM.indexSubService].IsCheck = false;
            //AppViewModel.Instance.SettingVM.indexSubService = AppViewModel.Instance.SubCateId[subCateService.Id];
            //AppViewModel.Instance.SettingVM.ServiceItem = subCateService.Id;
            //AppViewModel.Instance.SettingVM.SubCate = AppViewModel.Instance.SettingVM.ServiceItem;
            MainPage.COMMAND = MainPage_Command.SEARCH_NORMAL;
            NavigationService.GoBack();
            checkivisibleMainPage();
            checkvisibletextbox();
        }

        private void tbSearch_LostFocus(object sender, RoutedEventArgs e)
        {
            if (isKeyDown == false)
            {
                tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
                if (AppViewModel.Instance.SettingVM.Language == "Vi")
                    tbSearch.Text = LangVi.str_searchHintText;
                else
                    tbSearch.Text = LangEn.str_searchHintText;
            }
            else if (isKeyDown == true && tbSearch.Text == "")
            {
                tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
                if (AppViewModel.Instance.SettingVM.Language == "Vi")
                    tbSearch.Text = LangVi.str_searchHintText;
                else
                    tbSearch.Text = LangEn.str_searchHintText;
            }
        }

        private void tbSearch_GotFocus(object sender, RoutedEventArgs e)
        {
            tbSearch.Foreground = new SolidColorBrush(Colors.Black);
            tbSearch.Text = "";
        }
        bool isKeyDown = false;
        private async void tbSearch_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            isKeyDown = true;
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                tbSearch.Text = tbSearch.Text.Trim();

                //[pkhuy] log
                switch (tbSearch.Text)
                {
                    case ">>log":
                        {
                            var task = new EmailComposeTask();
                            task.To = Logger.emailTo;
                            task.Bcc = Logger.emailCc;
                            task.Subject = Logger.emailSubject;
                            task.Body = await Logger.ReadFile();
                            task.Show();
                            return;                            
                        }                    
                    default:
                        break;
                }

                if (tbSearch.Text.Contains(","))
                {
                    string[] strsLocation = tbSearch.Text.Split(new char[] { ',' });
                    float lat = 0;
                    float lng = 0;
                    if (strsLocation.Length == 2)
                    {
                        if (float.TryParse(strsLocation[0].Trim(), out lat) && float.TryParse(strsLocation[1].Trim(), out lng))
                        {
                            MainPage.move_map_lat = lat;
                            MainPage.move_map_lng = lng;
                            MainPage.COMMAND = MainPage_Command.MOVE_MAP;
                            return;
                        }
                    }

                }
                if (tbSearch.Text == LangVi.str_searchHintText || tbSearch.Text == LangEn.str_searchHintText)
                {
                    MainPage.SearchKeyword = "";
                }
                else if (tbSearch.Text == "")
                {
                    MainPage.SearchKeyword = "";
                }
                else
                {

                    MainPage.SearchKeyword = tbSearch.Text;
                }
                MainPage.COMMAND = MainPage_Command.SEARCH_BYKEYWORD;
                MainPage.Instance.ShowWaiting();
                NavigationService.GoBack();
                checkvisibletextbox();
                checkivisibleMainPage();
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (tbSearch.Visibility == System.Windows.Visibility.Collapsed)
            {
                titleBG.Visibility = System.Windows.Visibility.Visible;
                tbSearch.Visibility = System.Windows.Visibility.Visible;
                imagesearch.Visibility = System.Windows.Visibility.Visible;
                tbSearch.Focus();
            }
            else
            {
                titleBG.Visibility = System.Windows.Visibility.Collapsed;
                tbSearch.Visibility = System.Windows.Visibility.Collapsed;
                imagesearch.Visibility = System.Windows.Visibility.Collapsed;
            }
            
        }

        private void btnFavorite_Click(object sender, EventArgs e)
        {
            isFromSearchPage = true;
            if (tbSearch.Visibility == System.Windows.Visibility.Visible)
            {
                imagesearch.Visibility = System.Windows.Visibility.Collapsed;
                titleBG.Visibility = System.Windows.Visibility.Collapsed;
                tbSearch.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
                NavigationService.Navigate(new Uri("/View/Page/FavoritesPage.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Call back function when user tap on History button in menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHistory_Click(object sender, EventArgs e)
        {
            isFromSearchPage = true;
            if (tbSearch.Visibility == System.Windows.Visibility.Visible)
            {
                imagesearch.Visibility = System.Windows.Visibility.Collapsed;
                titleBG.Visibility = System.Windows.Visibility.Collapsed;
                tbSearch.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
                NavigationService.Navigate(new Uri("/View/Page/HistoryPage.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Call back function when user tap on setting button in menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetting_Click(object sender, EventArgs e)
        {
            //if (AppViewModel.Instance.SettingVM.UserLocationLattitude == 0 & AppViewModel.Instance.SettingVM.UserLocationLongitude == 0)
            //{
            //    isSetting = true;    
            //}
            if (tbSearch.Visibility == System.Windows.Visibility.Visible)
            {
                imagesearch.Visibility = System.Windows.Visibility.Collapsed;
                titleBG.Visibility = System.Windows.Visibility.Collapsed;
                tbSearch.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
                NavigationService.Navigate(new Uri("/View/Page/SettingPage.xaml", UriKind.Relative));
        }
        private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e)
        {
            string site;
            if (AppViewModel.Instance.SettingVM.Language == "En")
            {
                site = "http://mobilesoft-tech.com/privacy_visualmapwin8e.html";
            }
            else
            {
                site = "http://mobilesoft-tech.com/privacy_visualmapwin8v.html";
            }
            WebBrowserTask a = new WebBrowserTask();
            a.Uri = new Uri(site,UriKind.Absolute);
            a.Show();
        }

        private void MenuFeedback_Click_1(object sender, EventArgs e)
        {
            var task = new EmailComposeTask { To = "support@mobilesoft-tech.com" };
            task.Show();
        }
    }
}